package com.kuke.kukeuser.controller;

import com.kuke.kukecommon.entity.Result;
import com.kuke.kukeproduct.dto.ProductDTO;
import com.kuke.kukeuser.entity.User;
import com.kuke.kukeuser.remote.ProductControllerRemote;
import com.kuke.kukeuser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    ProductControllerRemote productControllerRemote;
    /**
     * 根据用户id获取用户
     * @return
     */
    @GetMapping("/getApiTest")
    public String getUserById(String id){
        return "apitest";
    }

    @GetMapping("/getUserList")
    public List<User> listUser(){
       List<User> users =  userService.lambdaQuery().eq(User::getName,"15510792994").list();
       return users;
    }

    @GetMapping("/getUserByPhone")
    public User getUserByPhone(String phone){
        User users =  userService.getUserByPhone(phone);
        return users;
    }
    //openfeign调用相关接口
    @GetMapping("getProductById")
    public Result getProductById(){

        return productControllerRemote.get(1L);
    }


    @PostMapping("addProduct")
    public Result addProduct(@RequestBody ProductDTO productDto){
        ProductDTO productDtoT = new ProductDTO();
        productDto.setProductName("粉笔");
        productDto.setDescription("彩色的粉笔");
        return productControllerRemote.add(productDtoT);
    }


}
